<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Bzbj extends Controller {
	
	public function action_like()
	{
		$like = 0;
		try {
			if (Request::$initial->method() == "POST"){
				$data = $this->request->post();
				$Marticle = Model::factory('Article');
				$re_up = $Marticle->plus_one(array('`like`'), $data['aid']);
				$err_msg = $re_up ? '成功' : '更新数据库失败';
				$code = $re_up ? 1 : 0;
				$re = $Marticle->get_by_aid($data['aid']);
				$like = isset($re['like']) ? $re['like'] : 0;
			}else {
				$err_msg = '请求错误';
				$code = 0;
			}
			
		}catch (Exception $e){
			Kohana_Exception::log($e);
			$err_msg = Kohana_Exception::text($e);
			$code = 0;
		}
		
		$result = array(
			'code' => $code,
			'msg' => $err_msg,
			'likenum' => $like
		);
		exit(json_encode($result));
	}
	
}